package com.sys.basics.config.shiro;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.session.ExpiredSessionException;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@Component
public class ShiroSessionListener implements SessionListener {

    private final AtomicInteger sessionCount = new AtomicInteger(0);

    @Override
    public void onStart(Session session) {
        sessionCount.incrementAndGet();
        log.info(">>>session连接: {}", session.getId());
    }
    @Override
    public void onStop(Session session) {
        sessionCount.decrementAndGet();
        log.info(">>>session断开: {}", session.getId());
    }
    @Override
    public void onExpiration(Session session) {
        sessionCount.decrementAndGet();
        log.info(">>>session过期: {}", session.getId(),session.getAttributeKeys());
    }
}